
#line 1 "..\main.c" /0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  
#line 1 "..\..\..\..\..\..\..\..\..\Keil_v5\C51\INC\reg51.h" /0






 
 
 
 
 
 
 sfr P0   = 0x80;
 sfr P1   = 0x90;
 sfr P2   = 0xA0;
 sfr P3   = 0xB0;
 sfr PSW  = 0xD0;
 sfr ACC  = 0xE0;
 sfr B    = 0xF0;
 sfr SP   = 0x81;
 sfr DPL  = 0x82;
 sfr DPH  = 0x83;
 sfr PCON = 0x87;
 sfr TCON = 0x88;
 sfr TMOD = 0x89;
 sfr TL0  = 0x8A;
 sfr TL1  = 0x8B;
 sfr TH0  = 0x8C;
 sfr TH1  = 0x8D;
 sfr IE   = 0xA8;
 sfr IP   = 0xB8;
 sfr SCON = 0x98;
 sfr SBUF = 0x99;
 
 
 
 
 sbit CY   = 0xD7;
 sbit AC   = 0xD6;
 sbit F0   = 0xD5;
 sbit RS1  = 0xD4;
 sbit RS0  = 0xD3;
 sbit OV   = 0xD2;
 sbit P    = 0xD0;
 
 
 sbit TF1  = 0x8F;
 sbit TR1  = 0x8E;
 sbit TF0  = 0x8D;
 sbit TR0  = 0x8C;
 sbit IE1  = 0x8B;
 sbit IT1  = 0x8A;
 sbit IE0  = 0x89;
 sbit IT0  = 0x88;
 
 
 sbit EA   = 0xAF;
 sbit ES   = 0xAC;
 sbit ET1  = 0xAB;
 sbit EX1  = 0xAA;
 sbit ET0  = 0xA9;
 sbit EX0  = 0xA8;
 
 
 sbit PS   = 0xBC;
 sbit PT1  = 0xBB;
 sbit PX1  = 0xBA;
 sbit PT0  = 0xB9;
 sbit PX0  = 0xB8;
 
 
 sbit RD   = 0xB7;
 sbit WR   = 0xB6;
 sbit T1   = 0xB5;
 sbit T0   = 0xB4;
 sbit INT1 = 0xB3;
 sbit INT0 = 0xB2;
 sbit TXD  = 0xB1;
 sbit RXD  = 0xB0;
 
 
 sbit SM0  = 0x9F;
 sbit SM1  = 0x9E;
 sbit SM2  = 0x9D;
 sbit REN  = 0x9C;
 sbit TB8  = 0x9B;
 sbit RB8  = 0x9A;
 sbit TI   = 0x99;
 sbit RI   = 0x98;
 
 
#line 17 "..\main.c" /0
 
  
#line 1 "..\..\..\..\..\..\..\..\..\Keil_v5\C51\INC\intrins.h" /0






 
 
 
 
 
 #pragma SAVE
 
 
#line 15 "..\..\..\..\..\..\..\..\..\Keil_v5\C51\INC\intrins.h" /1
 
 
 
#line 18 "..\..\..\..\..\..\..\..\..\Keil_v5\C51\INC\intrins.h" /0
 
 extern void          _nop_     (void);
 extern bit           _testbit_ (bit);
 extern unsigned char _cror_    (unsigned char, unsigned char);
 extern unsigned int  _iror_    (unsigned int,  unsigned char);
 extern unsigned long _lror_    (unsigned long, unsigned char);
 extern unsigned char _crol_    (unsigned char, unsigned char);
 extern unsigned int  _irol_    (unsigned int,  unsigned char);
 extern unsigned long _lrol_    (unsigned long, unsigned char);
 extern unsigned char _chkfloat_(float);
 
#line 29 "..\..\..\..\..\..\..\..\..\Keil_v5\C51\INC\intrins.h" /1
 
 
 
#line 32 "..\..\..\..\..\..\..\..\..\Keil_v5\C51\INC\intrins.h" /0
 
 extern void          _push_    (unsigned char _sfr);
 extern void          _pop_     (unsigned char _sfr);
 
 
 #pragma RESTORE
 
 
 
#line 18 "..\main.c" /0
 
  
#line 1 "..\main.h" /0
 
 
 
 typedef unsigned char BYTE;
 extern void SendData(BYTE dat);
 
 
#line 19 "..\main.c" /0
 
  
#line 1 "..\message.h" /0
 
 
 
 typedef char message;  
 
 
 
 extern void  PutMessage(message m);  
 extern void  PutMsg(char *strMsg);   
 extern void Message_task(void);  
 extern char HexToChar(char temp);
 
#line 20 "..\main.c" /0
 
  
#line 1 "..\..\..\..\..\..\..\..\..\Keil_v5\C51\INC\string.h" /0







 
 
 
 
 
 
 
 typedef unsigned int size_t;
 
 
 
 
 
 
 #pragma SAVE
 #pragma REGPARMS
 extern char  *strcat  (char *s1, const char *s2);
 extern char  *strncat (char *s1, const char *s2, size_t n);
 
 extern char   strcmp  (const char *s1, const char *s2);
 extern char   strncmp (const char *s1, const char *s2, size_t n);
 
 extern char  *strcpy  (char *s1, const char *s2);
 extern char  *strncpy (char *s1, const char *s2, size_t n);
 
 extern size_t strlen  (const char *);
 
 extern char  *strchr  (const char *s, char c);
 extern int    strpos  (const char *s, char c);
 extern char  *strrchr (const char *s, char c);
 extern int    strrpos (const char *s, char c);
 
 extern size_t strspn  (const char *s, const char *set);
 extern size_t strcspn (const char *s, const char *set);
 extern char  *strpbrk (const char *s, const char *set);
 extern char  *strrpbrk(const char *s, const char *set);
 extern char  *strstr  (const char *s, const char *sub);
 extern char  *strtok  (char *str, const char *set);
 
 extern char   memcmp  (const void *s1, const void *s2, size_t n);
 extern void  *memcpy  (void *s1, const void *s2, size_t n);
 extern void  *memchr  (const void *s, char val, size_t n);
 extern void  *memccpy (void *s1, const void *s2, char val, size_t n);
 extern void  *memmove (void *s1, const void *s2, size_t n);
 extern void  *memset  (void *s, char val, size_t n);
 #pragma RESTORE
 
 
#line 21 "..\main.c" /0
 
 
 
 
 
 
 
 typedef unsigned int WORD;
 typedef     unsigned char   u8;
 typedef     unsigned int    u16;
 typedef     unsigned long   u32;
 
 
 
 
 
 sfr T2H   = 0xd6;                
 sfr T2L   = 0xd7;                
 sfr P4   = 0xC0;
 sfr P5   = 0xC8;
 sfr P6   = 0xE8;
 sfr P7   = 0xF8;
 sfr P1M1 = 0x91;     
 sfr P1M0 = 0x92;     
 sfr P0M1 = 0x93;
 sfr P0M0 = 0x94;
 sfr P2M1 = 0x95;
 sfr P2M0 = 0x96;
 sfr P3M1 = 0xB1;
 sfr P3M0 = 0xB2;
 sfr P4M1 = 0xB3;
 sfr P4M0 = 0xB4;
 sfr P5M1 = 0xC9;
 sfr P5M0 = 0xCA;
 sfr P6M1 = 0xCB;
 sfr P6M0 = 0xCC;
 sfr P7M1 = 0xE1;
 sfr P7M0 = 0xE2;
 
 sfr  AUXR       =   0x8e;        
 
 sfr ADC_CONTR   =   0xBC;            
 sfr ADC_RES     =   0xBD;            
 sfr ADC_LOW2    =   0xBE;            
 sfr P1ASF       =   0x9D;            
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 u8 code t_display[]={                        
 
 0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71,
 
 0x00,0x40,0x76,0x1E,0x70,0x38,0x37,0x5C,0x73,0x3E,0x78,0x3d,0x67,0x50,0x37,0x6e,
 0xBF,0x86,0xDB,0xCF,0xE6,0xED,0xFD,0x87,0xFF,0xEF,0x46};     
 
 u8 code T_COM[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};       
 
 
 
 sbit    P_HC595_SER   = P4^0;    
 sbit    P_HC595_RCLK  = P5^4;    
 sbit    P_HC595_SRCLK = P4^3;    
 
 
 
 u8  LED8[8];         
 u8  display_index;   
 bit B_1ms;           
 
 u8  hour,minute,second;
 u16 msecond;
 
 
 
 
 void InitUart();
 void InitADC();
 void SendData(BYTE dat);
 BYTE GetADCResult(BYTE ch);
 void Delay(WORD n);
 void ShowResult(BYTE ch);
 void SendStr(char *strMsg);
 void main()
 {
 u8  i,k;
 
 P0M1 = 0;   P0M0 = 0;    
 P1M1 = 0;   P1M0 = 0;    
 P2M1 = 0;   P2M0 = 0;    
 P3M1 = 0;   P3M0 = 0;    
 P4M1 = 0;   P4M0 = 0;    
 P5M1 = 0;   P5M0 = 0;    
 P6M1 = 0;   P6M0 = 0;    
 P7M1 = 0;   P7M0 = 0;    
 
 AUXR = 0x80;     
 TH0 = (u8)((65536UL -(11059200L / 8000)) / 256);
 TL0 = (u8)((65536UL -(11059200L / 8000)) % 256);
 ET0 = 1;     
 TR0 = 1;     
 EA = 1;      
 
 display_index = 0;
 for(i=0; i<8; i++)  LED8[i] = 0;     
 k = 0;
 InitUart();                      
 InitADC();                       
 
 SendStr("My program V1.0 start!\r\n");
 Message_task();
 
 while (1)
 {
 if(B_1ms) 
 {
 PutMessage('{');
 
 B_1ms=0;
 PutMessage('-');
 ShowResult(3);               
 
 PutMessage('}');
 Message_task();
 }
 
 }
 }
 


 
 void ShowResult(BYTE ch)
 {
 unsigned char tempH,tempL;
 PutMessage('[');
 
 PutMessage(HexToChar(ch));
 
 
 tempH=GetADCResult(ch);
 tempL=ADC_LOW2;
 
 PutMessage(tempH);
 
 
 
 
 
 
 
 
 LED8[1] =tempH / 100 ; 
 LED8[2] = (tempH % 100) / 10;
 LED8[3] =tempH % 10;
 
 LED8[4] =tempL / 100 ; 
 LED8[5] = (tempL % 100) / 10;
 LED8[6] =tempL % 10;
 PutMessage(']');
 
 
 }
 


 
 BYTE GetADCResult(BYTE ch)
 {
 PutMessage('(');
 ADC_CONTR = 0x80 | 0x00 | ch | 0x08;
 _nop_();                         
 _nop_();
 _nop_();
 _nop_();
 while (!(ADC_CONTR & 0x10)); 
 ADC_CONTR &= ~0x10;          
 PutMessage(')');
 return ADC_RES;                  
 }
 


 
 void InitUart()
 {
 SCON = 0x5a;                 
 
 T2L = (65536 - (11059200L/4/115200));
 T2H = (65536 - (11059200L/4/115200)) >> 8;
 AUXR = 0x14;                 
 AUXR |= 0x01;                
 
#line 234 "..\main.c" /1
 
 
 
 
 
 
 
 
 
 
 
#line 245 "..\main.c" /0
 }
 


 
 void InitADC()
 {
 P1ASF = 0xff;                    
 ADC_RES = 0;                     
 ADC_CONTR = 0x80 | 0x00;
 Delay(2);                        
 }
 


 
 void SendData(BYTE dat)
 {
 while (!TI);                     
 TI = 0;                          
 SBUF = dat;                      
 }
 void SendStr(char *strMsg)
 {
 unsigned int i;
 unsigned int length = strlen(strMsg);
 
 for(i=0;i<length;i++) 
 {
 SendData(strMsg[i]);
 SendData(strMsg[i+1]);  
 i++;
 }
 }


 
 void Delay(WORD n)
 {
 WORD x;
 
 while (n--)
 {
 x = 5000;
 while (x--);
 }
 }
 
 
 
 
 
 void Send_595(u8 dat)
 {
 u8  i;
 PutMessage('@');
 PutMessage(101);
 
 for(i=0; i<8; i++)
 {
 dat <<= 1;
 P_HC595_SER   = CY;
 P_HC595_SRCLK = 1;
 P_HC595_SRCLK = 0;
 }
 }
 
 
 void DisplayScan(void)
 {   
 SendStr("DisplayScan()");
 
 
 
 Send_595(~T_COM[display_index]);                 
 Send_595(t_display[LED8[display_index]]);    
 
 P_HC595_RCLK = 1;
 P_HC595_RCLK = 0;                            
 if(++display_index >= 8)    display_index = 0;   
 }
 
 
 
 void timer0 (void) interrupt 1
 {
 DisplayScan();   
 B_1ms = 1;       
 
 }
